package com.guxingke.gblog.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.guxingke.gblog.dto.AboutDto;
import com.guxingke.gblog.service.ArticleService;
import com.guxingke.gblog.service.impl.ArticleServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class AboutManageAction extends ActionSupport implements
		ServletRequestAware {
	private static final long serialVersionUID = 1L;
	private HttpServletRequest request;
	private ArticleService articleService = new ArticleServiceImpl();

	private AboutDto about;
	private String mainPage;

	@Override
	public String execute() throws Exception {
		about = articleService.getAbout();
		mainPage = "template/about/manage-detail.jsp";
		return SUCCESS;
	}

	public String preSave() throws Exception {
		about = articleService.getAbout();
		request.setAttribute("mainPage", "template/about/manage-save.jsp");
		mainPage = "template/about/manage-save.jsp";
		return SUCCESS;
	}

	public String save() throws Exception {
		articleService.updateAbout(about);
		mainPage = "template/about/manage-detail.jsp";
		return "otherSuccess";
	}

	public AboutDto getArticle() {
		return about;
	}

	public void setArticle(AboutDto about) {
		this.about = about;
	}

	public String getMainPage() {
		return mainPage;
	}

	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
}
